/*
 * @lc app=leetcode.cn id=2037 lang=typescript
 *
 * [2037] 使每位学生都有座位的最少移动次数
 */

// @lc code=start
function minMovesToSeat(seats: number[], students: number[]): number {
    const sortedSeats = seats.sort((a, b) => a - b);
    const sortedStu = students.sort((a, b) => a - b);
    let count = 0;
    for (let i = 0; i < sortedSeats.length; i++) {
        const stu = sortedStu[i];
        const seat = sortedSeats[i];
        count += Math.abs(stu - seat);
    }
    return count;
}
// @lc code=end
